package com.example.cloudpracticeplatform.mapper;

import com.example.cloudpracticeplatform.entity.Student;
import com.example.cloudpracticeplatform.entity.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {
    @Insert("INSERT INTO students(username, password, email) VALUES(#{username}, #{password}, #{email})")
    @Options(useGeneratedKeys = true, keyProperty = "studentId")
    int insert(Student student);

    @Update("UPDATE students SET username=#{username}, password=#{password}, email=#{email} WHERE student_id=#{studentId}")
    int update(Student student);

    @Delete("DELETE FROM students WHERE student_id=#{studentId}")
    int delete(Integer studentId);

    @Select("SELECT student_id, username, password, email FROM students WHERE student_id=#{studentId}")
    Student findById(Integer studentId);

    @Select("SELECT student_id, username, password, email FROM students LIMIT #{offset}, #{limit}")
    List<Student> findAll(int offset, int limit);
    
    @Select("SELECT student_id, username, password, email FROM students WHERE username = #{username}")
    Student findByUsername(String username);
}